package org.nanquan.dotjava.view.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;


public class EncodingFilter implements Filter {
	
	private String requestencoding="UTF-8";
	
	private String responseencoding="UTF-8";

	public void destroy() {
		// TODO 自动生成方法存根

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain arg2) throws IOException, ServletException {
		// TODO 自动生成方法存根
//		System.out.println(this.requestencoding);
//		System.out.println(this.responseencoding);
//		request.setCharacterEncoding(this.requestencoding);
//		response.setCharacterEncoding(this.responseencoding);
//		System.out.println("doFilter--------------------------------------");
		arg2.doFilter(request, response);
//		HibernateSessionFactory.getSession().close();
//		HibernateSessionFactory.closeSession();
	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO 自动生成方法存根
		if(arg0.getInitParameter("requestencoding")!=null)
		this.requestencoding=arg0.getInitParameter("requestencoding");
		if(arg0.getInitParameter("responseencoding")!=null)
		this.responseencoding=arg0.getInitParameter("responseencoding");
	}

}
